package com.ershijin.config;

import com.ershijin.my.UserDetailsExpand;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.jwt.JwtClaimsSet;
import org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;

import static org.springframework.security.config.Customizer.withDefaults;

@EnableWebSecurity
public class DefaultSecurityConfig {

    @Bean
    SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests(authorizeRequests ->
          authorizeRequests.mvcMatchers("/userinfo").permitAll()
                  .anyRequest().authenticated()
        )
          .formLogin(withDefaults());

        return http.build();
    }

//    @Bean
//    UserDetailsService users() {
////        UserDetails user = User.withDefaultPasswordEncoder()
////          .username("admin")
////          .password("password")
////          .roles("USER")
////          .build();
//        UserDetails user = User.withDefaultPasswordEncoder()
//          .username("admin")
//          .password("password")
//          .roles("USER","order")
//          .build();
//        return new InMemoryUserDetailsManager(user);
//
////        PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
////
////        UserDetailsExpand userDetailsExpand = new UserDetailsExpand("admin", encoder.encode("password"), AuthorityUtils.createAuthorityList("USER"));
////
////
////
////        userDetailsExpand.setId(1L);
////
////        return new InMemoryUserDetailsManager(userDetailsExpand);
//    }

}
